package com.jushu.storbox;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * use this activity to process all the ui with same title view
 * 
 */
public class BaseTitleActivity extends Activity {

	protected final static String TAG = BaseTitleActivity.class.getSimpleName();

	View returnGroup = null;
	ImageView returnIcon = null;
	TextView currentTitle = null;
	View rightGroup = null;
	ImageView rightIcon = null;
	TextView rightOperation = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
	}

	@Override
	public final void setContentView(int layoutResID) {
		super.setContentView(layoutResID);
		returnGroup = findViewById(R.id.action_title_return_button);
		returnIcon = (ImageView) findViewById(R.id.action_title_return_icon);
		currentTitle = (TextView) findViewById(R.id.action_title_name_button);
		rightGroup = findViewById(R.id.action_title_right_button);
		rightIcon = (ImageView) findViewById(R.id.action_title_right_icon);
		rightOperation = (TextView) findViewById(R.id.action_title_right_operation);
		returnGroup.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				onLeftClicked(arg0);
			}
		});
		rightGroup.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				onRightClicked(arg0);
			}
		});
	}

	protected void setLeftButtonClickable(boolean clickable) {
		returnGroup.setClickable(clickable);
	}

	protected void setRightButtonClickable(boolean clickable) {
		rightGroup.setClickable(clickable);
	}

	protected void onLeftClicked(View clickView) {
		Log.i(TAG, "return is clicked!");
	}

	protected void onRightClicked(View clickView) {
		Log.i(TAG, "right is clicked!");
	}

	protected final void setCurrentTitle(int stringId) {
		if (currentTitle != null) {
			currentTitle.setText(stringId);
		}
	}

	protected final void setCurrentTitle(String titleStr) {
		if (currentTitle != null) {
			currentTitle.setText(titleStr);
		}
	}

	protected final void setRightText(int stringId) {
		if (rightOperation != null) {
			rightOperation.setText(stringId);
		}
	}

	protected final void setCurrentRightIcon(int iconResId) {
		if (rightIcon != null) {
			rightIcon.setImageResource(iconResId);
		}
	}

	/** left icon & text , right icon */
	protected final void switchTypeOne() {
		returnIcon.setVisibility(View.VISIBLE);
		currentTitle.setVisibility(View.VISIBLE);
		rightIcon.setVisibility(View.VISIBLE);
		rightOperation.setVisibility(View.GONE);
	}
protected  void  switchInvite() {
	returnIcon.setVisibility(View.VISIBLE);
	currentTitle.setVisibility(View.VISIBLE);
	rightIcon.setVisibility(View.GONE);
	rightOperation.setVisibility(View.GONE);
}
	/** left icon & text , right text */
	protected final void switchTypeTwo() {
		returnIcon.setVisibility(View.VISIBLE);
		currentTitle.setVisibility(View.VISIBLE);
		rightIcon.setVisibility(View.GONE);
		rightOperation.setVisibility(View.VISIBLE);
	}

	/** left text , right icon */
	protected final void switchTypeThree() {
		returnIcon.setVisibility(View.GONE);
		currentTitle.setVisibility(View.VISIBLE);
		rightIcon.setVisibility(View.VISIBLE);
		rightOperation.setVisibility(View.GONE);
	}

	/** left text , right text */
	protected final void switchTypeFour() {
		returnIcon.setVisibility(View.GONE);
		currentTitle.setVisibility(View.VISIBLE);
		rightIcon.setVisibility(View.GONE);
		rightOperation.setVisibility(View.VISIBLE);
	}

	/** left icon & text , right null */
	protected final void switchTypeFive() {
		returnIcon.setVisibility(View.VISIBLE);
		currentTitle.setVisibility(View.VISIBLE);
		rightIcon.setVisibility(View.GONE);
		rightOperation.setVisibility(View.GONE);
	}
}
